<?php

namespace app\admin\model;

use think\Model;


class UserClass extends Model
{

    

    

    // 表名
    protected $name = 'user_class';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'absent_text',
        'grade_text',
        'stime_text',
        'etime_text'
    ];
    

    
    public function getAbsentList()
    {
        return ['0' => __('Absent 0'), '1' => __('Absent 1')];
    }

    public function getGradeList()
    {
        return ['0' => __('Grade 0'), '1' => __('Grade 1'), '2' => __('Grade 2'), '3' => __('Grade 3')];
    }


    public function getAbsentTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['absent']) ? $data['absent'] : '');
        $list = $this->getAbsentList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGradeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['grade']) ? $data['grade'] : '');
        $list = $this->getGradeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stime']) ? $data['stime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['etime']) ? $data['etime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setStimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function venue()
    {
        return $this->belongsTo('Venue', 'venue_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function term()
    {
        return $this->belongsTo('Term', 'term_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function course()
    {
        return $this->belongsTo('Course', 'course_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function courseplan()
    {
        return $this->belongsTo('CoursePlan', 'course_plan_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function courseproject()
    {
        return $this->belongsTo('CourseProject', 'course_project_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function coursenode()
    {
        return $this->belongsTo('CourseNode', 'course_node_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
